//
//  FoodDetailViewController.m
//  ArtOfLiving
//
//  Created by xalo on 16/5/1.
//  Copyright © 2016年 刘虎. All rights reserved.
//

#import "FoodDetailViewController.h"
#import "FoodMainModel.h"
#import "FoodListView.h"
#import "FoodNutritionDataModel.h"

@interface FoodDetailViewController ()

@property (nonatomic, strong) FoodMainModel *model;                 //此界面需要显示的数据模型

@end

@implementation FoodDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self fetchDataSourceWithUrlString:[kFoodDetail stringByAppendingString:[NSString stringWithFormat:@"%@/",self.Id]]];
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
}

- (void)didReceiveMemoryWarning {
    
    [super didReceiveMemoryWarning];
}


#pragma mark - -----列表详情-------
- (void)createTableWithInfoArray:(NSArray *)infoArr {
    
    FoodListView *listTableView = [[FoodListView alloc] initWithListFrame:CGRectZero listArray:infoArr];
    [self.view addSubview:listTableView];
}

#pragma mark - -------数据请求与解析-------
- (void)fetchDataSourceWithUrlString:(NSString *)urlString {
    
    [LHDataRequestTools getFetchDataWithUrlString:urlString paramenters:nil success:^(id data) {
        
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
        FoodMainModel *model = [[FoodMainModel alloc]init];
        [model setValuesForKeysWithDictionary:dic[@"data"]];
        
        [self createTableWithInfoArray:model.nutritionMArr];
        
    } fail:^{
        
        NSLog(@"食谱详情请求出错");
    } view: self.view];
}


#pragma mark - -------懒加载------

- (FoodMainModel *)model {
    
    if (!_model) {
        
        _model = [[FoodMainModel alloc] init];
    }
    return _model;
}

@end
